package cn.ulyer.common.utils;

import cn.ulyer.common.security.LoginUser;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;

public class SecurityUtil {

    private SecurityUtil(){}

    /**
     * 登录状态获取
     * @return
     */
    public static LoginUser getUser(){
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        return authentication instanceof UsernamePasswordAuthenticationToken  ? (LoginUser) authentication.getPrincipal() : null;
    }



}
